package com.AEWMS.Utlis;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * @author lhs
 * @create 2021/2/19 22:08
 */
public class DbCon {

    private static final String DBDRIVER = "com.mysql.jdbc.Driver";
    private static final String DBURL = "jdbc:mysql://39.97.223.111:3306/aewms?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8";
    private static final String DBUSER = "incimo";
    private static final String DBPASSWORD = "972784674t";
    private final Connection conn;

    /**
     * 返回 conn 对象
     */
    public DbCon() throws Exception {
        try {
            Class.forName(DBDRIVER);
            this.conn = DriverManager.getConnection(DBURL, DBUSER, DBPASSWORD);
        } catch (Exception e) {
            throw e;
        }
    }

    public Connection getConnection() {
        return this.conn;
    }

    public void close() throws Exception {
        if (this.conn != null) {
            try {
                this.conn.close();
            } catch (Exception e) {
                throw e;
            }
        }
    }
}
